package com.genesis.yunnanji.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.bean.HomePageListBean;
import com.genesis.yunnanji.config.GenesisApiConfig;

import java.util.ArrayList;
import java.util.List;

public class CoverFlowAdapter extends BaseAdapter {

    private List<HomePageListBean.ResultBean.ListBean.AdvertListBean> mData = new ArrayList<>(0);
    private Context mContext;

    public CoverFlowAdapter(Context context, List<HomePageListBean.ResultBean.ListBean.AdvertListBean> data) {
        mContext = context;
        mData = data;
    }


    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int pos) {
        return mData.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View rowView = convertView;

        if (rowView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.item_coverflow, null);

            ViewHolder viewHolder = new ViewHolder();

            viewHolder.image = (ImageView) rowView
                    .findViewById(R.id.image);
            rowView.setTag(viewHolder);
        }

        ViewHolder holder = (ViewHolder) rowView.getTag();

        Glide.with(mContext).load(GenesisApiConfig.PIC_HOST + mData.get(position).getAdvert_img()).into(holder.image);


        return rowView;
    }


    static class ViewHolder {

        public ImageView image;
    }
}